#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>

void multi_sink_example()
{
    //创建一个标准输出的落地方向对象
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    //设置日志等级
    console_sink->set_level(spdlog::level::debug);
    //设置格式
    console_sink->set_pattern("[%n][%H:%M:%S][%t][%-8l] %v");
    //创建日志器
    auto logger = std::make_shared<spdlog::logger>("multi_sink",console_sink);
    logger->trace("你好！{}", "小明");
    logger->debug("你好！{}", "小明");
    logger->info("你好！{}", "小明");
    logger->warn("你好！{}", "小明");
    logger->error("你好！{}", "小明");
    logger->critical("你好！{}", "小明");
    std::cout << "日志输出演示完毕！\n";
}

void test2()
{
    //设置全局的刷新策略
    //每秒刷新
    spdlog::flush_every(std::chrono::seconds(1));
    //设置全局的刷新时机
    spdlog::flush_on(spdlog::level::level_enum::debug);
    //设置全局的日志输出级别
    spdlog::set_level(spdlog::level::level_enum::debug);
    auto logger = spdlog::basic_logger_mt("file_logger","sync.log");

    //进行日志输出
    logger->trace("你好！{}", "小明");
    logger->debug("你好！{}", "小明");
    logger->info("你好！{}", "小明");
    logger->warn("你好！{}", "小明");
    logger->error("你好！{}", "小明");
    logger->critical("你好！{}", "小明");
    std::cout << "日志输出演示完毕！\n";
}


int main()
{
    multi_sink_example();
   // test2(); 
    return 0;
}